<?php 
/**
 * This file is part of workerman.
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the MIT-LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @author walkor<walkor@workerman.net>
 * @copyright walkor<walkor@workerman.net>
 * @link http://www.workerman.net/
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
 */

use \Workerman\Worker;
use \GatewayWorker\Gateway;

// 获取配置
$gatewayConfig = config('im.gateway');
// gateway 进程，这里使用Text协议，可以用telnet测试

// 指定websocket协议
$gateway = new Gateway($gatewayConfig['protocol'] . $gatewayConfig['protocol_ip'] . ':' . $gatewayConfig['protocol_port']);
// $gateway = new Gateway("tcp://0.0.0.0:8585");
// gateway名称，status方便查看
$gateway->name = $gatewayConfig['name'];
// gateway进程数
$gateway->count = $gatewayConfig['count'];
// 本机ip，分布式部署时使用内网ip
$gateway->lanIp = $gatewayConfig['lanIp'];
// 内部通讯起始端口，假如$gateway->count=4，起始端口为4000
// 则一般会使用4000 4001 4002 4003 4个端口作为内部通讯端口 
$gateway->startPort = $gatewayConfig['startPort'];
// 服务注册地址
$gateway->registerAddress = $gatewayConfig['registerAddressIp'] . ':' . $gatewayConfig['registerAddressPort'];
// 其中pingNotResponseLimit = 0代表服务端允许客户端不发送心跳，服务端不会因为客户端长时间没发送数据而断开连接。
// 如果pingNotResponseLimit = 1，则代表客户端必须定时发送数据给服务端，否则pingNotResponseLimit*pingInterval=55秒内没有任何数据发来则关闭对应连接，并触发onClose。
$gateway->pingNotResponseLimit = $gatewayConfig['pingNotResponseLimit'];

// 心跳间隔
$gateway->pingInterval = $gatewayConfig['pingInterval'];

// 心跳数据
if (!empty($gatewayConfig['pingData'])) {
    $gateway->pingData = $gatewayConfig['pingData'];
}


// 当客户端连接上来时，设置连接的onWebSocketConnect，即在websocket握手时的回调
$gateway->onConnect = function($connection)
{
    $connection->onWebSocketConnect = function($connection , $http_header)
    {
    
    };
}; 


// 如果不是在根目录启动，则运行runAll方法
if(!defined('GLOBAL_START'))
{
    Worker::runAll();
}

